package com.leapp.sk.ui.activity.classs

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import cc.vv.lkbasecomponent.http.LKHttp
import cc.vv.lkbasecomponent.http.lib.setting.Settings
import cc.vv.lklibrary.http.base.okhttpfactory.plugins.httpplugin.MediaTypeWrap
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.example.util.ObjectProcessingUtil
import com.leapp.sk.R
import com.leapp.sk.app.GET_CLASS_MEMBER
import com.leapp.sk.bean.MemberAllUserDataEntity
import com.leapp.sk.bean.request.MemberAllUserListRequest
import com.leapp.sk.bean.response.MemberAllUserListResponse
import com.leapp.sk.binder.BaseBinder
import com.example.util.finallist.CLASS_ID
import com.leapp.sk.viewdelegate.classs.ClassMemberDelegate
/**
 * 班级成员
 * @author  chaohaipeng  on 2018/7/31.
 */
class ClassMemberActivity:BaseActivityMVP<ClassMemberDelegate>(){
    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_class_member_title))
    }

    override fun initDate() {
        val stringExtra = intent?.getStringExtra(CLASS_ID)
        getHttpData(stringExtra)
    }

    override fun bindEvenListener() {
        viewDelegate.setOnClickListener(View.OnClickListener {
            viewDelegate.clearContent()
        }, R.id.iv_acm_clear)
    }

    override fun getDelegateClass(): Class<ClassMemberDelegate> {
        return ClassMemberDelegate::class.java

    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }
    private fun getHttpData(classID:String?) {
        val memberAllUserListRequest = MemberAllUserListRequest()
        if (TextUtils.isEmpty(classID)){
            memberAllUserListRequest.classIdOrGroupId = memberAllUserListRequest.classId
        }else{
            memberAllUserListRequest.classIdOrGroupId = classID!!
        }
        memberAllUserListRequest.name = ""
        memberAllUserListRequest.type = 1
        LKHttp.post(GET_CLASS_MEMBER, memberAllUserListRequest, MemberAllUserListResponse::class.java, object : BaseCallBack<MemberAllUserListResponse>(this) {
            override fun onSuccess(url: String?, resultText: String?, obj: MemberAllUserListResponse?) {
                super.onSuccess(url, resultText, obj)
                if (obj?.code == 200) {
                    val memberAllUserDataEntity: MemberAllUserDataEntity = ObjectProcessingUtil.objMandatoryConversionClass(obj?.data, MemberAllUserDataEntity::class.java)
                    val classMsg = memberAllUserDataEntity?.classMsg
                 viewDelegate?.initAdapter(classMsg)

                }else{
                    LKToastUtil.showToastShort(obj?.message)
                }
            }
            override fun onFailure(url: String?, isLoading: Boolean, exceptionStr: String?) {
                super.onFailure(url, isLoading, exceptionStr)
                LKToastUtil.showToastShort(resources.getString(R.string.app_net_erro))
            }
        }
                , false, Settings(MediaTypeWrap.MEDIA_TYPE_FORM))
    }
}